<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>插入排序</title>
</head>
<body>
    <script>
        function Sort(array) {
            console.log('开始抓牌码牌');
            for(let i = 1; i < array.length; i++) {
                let ai = array[i];
                for(let j = i -1; j > 0; j--) {
                    console.log(`${array[j]} < ${array[j-1]} 比较`);
                    
                    if(array[j] < array[j-1]) {
                        let other = array[j];
                        array[j] = array[j-1];
                        array[j-1] = other;
                    } else {
                        break;
                    }
                    console.log(array);
                }
            }
        }


        let arr = [2, 4, 6, 3, 9, 1, 7];
        Sort(arr);
        console.log(arr);
    </script>
</body>
</html>